/**
 * Project Name:cnsy-url-short-service
 * File Name:PageNodeStatusController.java
 * Package Name:cn.cnsy123.shorturls.api.controller.page 
 * Date: 2020年4月16日-下午2:44:25
 * Copyright (c) 2020, yangpengfei@360@126.com All Rights Reserved. 
 *
 */

package cn.cnsy123.shorturls.api.controller.page;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

import cn.cnsy123.shorturls.api.controller.param.ReportNodeBrowseLogParam;
import cn.cnsy123.shorturls.api.controller.vo.BaseResponse;
import cn.cnsy123.shorturls.constants.SessionInfoConstants;

/**
 * ClassName: PageNodeStatusController
 * 
 * @author yangpengfei
 * @date 2020年4月16日-下午2:44:25
 * @version 1.0
 * @since JDK 1.7
 */
@Controller
public class PageNodeStatusController {
    
    private static final Logger logger = LoggerFactory.getLogger(PageNodeStatusController.class); 
    
    @RequestMapping(value = "/report/node")
    @ResponseBody
    public BaseResponse reportPageBrowseLog(@RequestBody ReportNodeBrowseLogParam reportNode,HttpServletRequest request) {
        BaseResponse baseResponse = new BaseResponse(100,"用户状态已过期");
        Object attribute = request.getSession().getAttribute(SessionInfoConstants.SESSION_USER_BEAN);
        if(attribute != null) {
            logger.info("上报节点数据参数:{}",JSON.toJSONStringWithDateFormat(reportNode, "yyyy-MM-dd HH:mm:ss", SerializerFeature.WriteDateUseDateFormat,SerializerFeature.WriteMapNullValue));
            request.getSession().setAttribute(SessionInfoConstants.SESSION_VISIT_NODE, reportNode.getNowNodeId());
            request.getSession().setAttribute(SessionInfoConstants.SESSION_VISIT_NODE_ADDR, reportNode.getVisitAddr());
            baseResponse.setCode(200);
            baseResponse.setMsg("上报成功");
        }
        return baseResponse;
    }

}
